

import UdpService from '../services/udp.js'
/**
 * @发送消息到udp服务器
 * @connectUdpServer建立连接发送消息
 * @connectUdpServer发送终端消息
 */
class RendererManager {
    static hostPort = {
        ip:'',
        port:0
    }
   static udpService = UdpService.getInstance() 

   static connectUdpServer(message){   
        if((this.hostPort.ip === '' || this.hostPort.port === 0)&&message.address){
            this.hostPort.ip = message.address
            this.hostPort.port = message.port
          }
        return this.udpService.sendMessage({
            message: JSON.stringify(message),
            port:this.hostPort.port,
            host: this.hostPort.ip
        })
    }

    static   sendInputMessage(message){
        return this.udpService.sendMessage({
            message: JSON.stringify(message),
            port:this.hostPort.port,
            host: this.hostPort.ip
        })
    }
}

export default RendererManager 